<template>
  <div class="child">
    <h2>我是Child组件</h2>
    <h3>我的玩具：{{ toy }}</h3>
    <h3>我的电脑：{{ computer }}</h3>
    <button @click="$emit('send-toy',toy)">把玩具给父</button>
    <button @click="$emit('send-computer',computer)">把电脑给父</button> | 
    <button @click="test1">解绑send-toy事件</button>
    <button @click="test2">解绑send-computer事件</button>
    <button @click="test3">解绑send-toy、send-computer事件</button>
    <button @click="test4">解绑所有事件</button>
  </div>
</template>

<script>
  export default {
    name:'Child',
    data() {
      return {
        toy:'奥特曼',
        computer:'联想'
      }
    },
    methods: {
      test1(){
        this.$off('send-toy')
      },
      test2(){
        this.$off('send-computer')
      },
      test3(){
        this.$off(['send-toy','send-computer'])
      },
      test4(){
        this.$off()
      }
    },
  }
</script>

<style scoped>
  .child {
    background-color: skyblue;
    padding: 10px;
    border-radius: 10px;
    box-shadow: 0 0 10px;
  }
  button {
    margin: 0 2px;
  }
</style>